package com.sensologyhome_all.util;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.View;

import com.sensologyhome_all.R;


public class DialogUtil {
    private static ProgressDialog loadingDialog;
    public static ProgressDialog setProgressDialog(Activity activity) {
        loadingDialog = new ProgressDialog(activity);
        String loadingText = activity.getString(R.string.loadingtext);
        loadingDialog.setMessage(loadingText);
        loadingDialog.setCanceledOnTouchOutside(false);
        return loadingDialog;
    }

    public static ProgressDialog setProgressDialog(Activity activity, String Message, boolean Cancelable,
                                                   boolean CanceledOnTouchOutside) {
        loadingDialog = new ProgressDialog(activity);
        loadingDialog.setMessage(Message);
        loadingDialog.setCancelable(Cancelable);
        loadingDialog.setCanceledOnTouchOutside(CanceledOnTouchOutside);
        return loadingDialog;
    }

    public static void cancleLoadingDialog(){
        if(loadingDialog!=null){
            try {
                loadingDialog.cancel();
            } catch (Exception e) {
            }
        }
    }






    public static AlertDialog createAlertDialog(Context context, int message) {
        return createAlertDialog(context, R.string.tips, message, R.string.ensure, R.string.cancel);
    }

    public static AlertDialog createAlertDialog(Context context, int title, int message, int positive, int negative) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title).setMessage(message).setPositiveButton(positive, null).setNegativeButton(negative, null);
        return builder.create();
    }

    public static AlertDialog createAlertDialog(Context context, View view) {
        return createAlertDialog(context, view, R.string.tips, R.string.ensure, R.string.cancel);
    }

    public static AlertDialog createAlertDialog(Context context, View view, int title, int positive, int negative) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title).setView(view).setPositiveButton(positive, null).setNegativeButton(negative, null);
        return builder.create();
    }



}